package com.homegoods.discover.widget;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.FrameLayout;

import com.homegoods.discover.R;
import com.homegoods.discover.databinding.DiscoverVideoViewBinding;
import com.homegoods.discover.model.VideoModel;
import com.kedll.library.util.BindingUtil;

import cn.jzvd.Jzvd;

/**
 * @author QiQi
 * @ClassName: DiscoverVideoView
 * @date 2018/9/11
 * @description 视频
 */
public class DiscoverVideoView extends FrameLayout {
    DiscoverVideoViewBinding viewBinding;

    public DiscoverVideoView(@NonNull Context context) {
        this(context, null);
    }

    public DiscoverVideoView(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public DiscoverVideoView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    private void initView(Context context) {
        viewBinding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.discover_video_view, this, true);
    }

    public void setData(VideoModel data) {
        viewBinding.setModel(data);
        setVideoUrl(data.getUrl(), data.getTitle(), data.getUrl());
    }

    private void setVideoUrl(String videoUrl, String title, String videoThumb) {
        viewBinding.videoplayer.setUp(videoUrl, title, Jzvd.SCREEN_WINDOW_LIST);
        BindingUtil.loadImageNoTransform(viewBinding.videoplayer.thumbImageView, videoThumb, null, null);
    }
}


